import uvicorn
from fastapi import FastAPI, Depends

from config import settings
from config.log_config import init_log
from utils import handler_error, CORS, middlewares
from utils.docs2_oauth2 import MyOAuth2PasswordBearer


from api.user_mgt import router


# pip install dynaconf

class Server:
    def __init__(self):
        init_log()
        #
        my_oauth2 = MyOAuth2PasswordBearer(tokenUrl="/api/auth/", schema="JWT")
        self.app = FastAPI(dependencies=[Depends(my_oauth2)])
        self.app = FastAPI()

    def init_app(self):
        handler_error.init_handler_errors(self.app)
        middlewares.init()
        router.init_routers(self.app)

    def run(self):
        self.init_app()
        uvicorn.run(app=self.app, host=settings.HOST, port=settings.PORT)


if __name__ == '__main__':
    Server
